package com.ophiux.cs.application.consultOrder.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ophiux.cs.application.consultOrder.dto.ApplayCSPublishRequest;
import com.ophiux.cs.application.consultOrder.dto.ApplayCSPublishResponse;
import com.ophiux.cs.application.consultOrder.service.IApplayCSPublishAppService;
import com.ophiux.cs.application.core.Result;
import com.ophiux.cs.application.core.ResultEnum;
import com.ophiux.cs.domain.consultOrder.model.entity.CSOnlineRecords;
import com.ophiux.cs.domain.consultOrder.model.entity.CSRecordDescription;
import com.ophiux.cs.domain.consultOrder.repositories.ICSOnlineRecordRepository;
import com.ophiux.utils.common.ShiftUtils;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class ApplayCSPublishAppService implements IApplayCSPublishAppService{
	@Autowired
	ICSOnlineRecordRepository csOnlineRecordRepository;
	
	@Override
	public Result<ApplayCSPublishResponse> ApplayCSPublish(ApplayCSPublishRequest dto) {
//		ApplayCSPublishResponse resp = new ApplayCSPublishResponse();
		try {
			if(!dto.isParamValid()) {
				return Result.fail(ResultEnum.requestParamFail);
			}
			
			CSOnlineRecords obj = new CSOnlineRecords();
			obj = (CSOnlineRecords) ShiftUtils.objToNewObj(dto, CSOnlineRecords.class);			
			obj.addBuilder();
			
			CSRecordDescription obj1 = new CSRecordDescription();
			obj1 = (CSRecordDescription) ShiftUtils.objToNewObj(dto, CSRecordDescription.class);
			obj1.setRECORD_ID(obj.getRECORD_ID());
			
			csOnlineRecordRepository.save(obj,obj1);
			
			
			
		} catch (Exception e) {
			log.info("程序异常：",e);
			e.printStackTrace();
			return Result.fail(ResultEnum.requestException);
		}
		return Result.success();
	}

}
